package sunmi.payment.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import mi.payment.R;

/**
 * @author Lee64 on 2017/5/25.
 */

public class SdkStateDialog extends Dialog {

    public SdkStateDialog(Context context, String text) {
        this(context, sunmi.sunmiui.R.style.defaultDialogStyle, text);
    }

    private SdkStateDialog(Context context, int theme, String text) {
        super(context, theme);
        init(text);
    }

    private void init(String text) {
        setContentView(R.layout.dialog_sdk_state);
        if (getWindow() != null) {
            getWindow().getAttributes().gravity = Gravity.CENTER;
            getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        }
        // 点击空白不取消
        setCanceledOnTouchOutside(false);
        // 点击返回按钮不取消
        setCancelable(false);

        TextView tvSdkState = (TextView) findViewById(R.id.tv_state);
        if (TextUtils.isEmpty(text)) {
            tvSdkState.setText(getContext().getString(R.string.sdk_state_connected));
        } else {
            tvSdkState.setText(text);
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

}
